from django.db import models

class Tag(models.Model):
    """标签模型"""
    
    # 标签类型选项
    TYPE_CHOICES = (
        ('tech', '技术'),
        ('topic', '主题'),
        ('other', '其他'),
    )
    
    name = models.CharField('名称', max_length=100)
    slug = models.SlugField('标识', max_length=100, unique=True)
    description = models.TextField('描述', blank=True)
    type = models.CharField('类型', max_length=20, choices=TYPE_CHOICES, default='other')
    color = models.CharField('颜色', max_length=20, default='#666666')
    icon = models.CharField('图标', max_length=50, blank=True)
    order_index = models.IntegerField('排序', default=0)
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    updated_at = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        verbose_name = '标签'
        verbose_name_plural = verbose_name
        ordering = ['order_index', 'id']

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return f'/tag/{self.slug}/' 